﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EmbeddedLanguage
{
    public delegate TOut Del_2x1<TInput1, TInput2, TOut>(TInput1 input1, TInput2 input2);


    public class DelCache_2x1<TInput1, TInput2, TOut>
    {
        [ThreadStatic]
        private static Dictionary<Del_2x1<TInput1, TInput2, TOut>, Func<TInput1, TInput2, TOut>> DelegateCache;

        private static Dictionary<Del_2x1<TInput1, TInput2, TOut>, Func<TInput1, TInput2, TOut>> DelegateCacheNN
        {
            get
            {
                if (DelegateCache == null) DelegateCache = new Dictionary<Del_2x1<TInput1, TInput2, TOut>, Func<TInput1, TInput2, TOut>>();
                return DelegateCache;
            }
        }

        public static Func<TInput1, TInput2, TOut> GetFn(Del_2x1<TInput1, TInput2, TOut> deleg)
        {
            if (DelegateCache == null)
            {
                throw new NotImplementedException();
            }
            if (!DelegateCache.ContainsKey(deleg))
            {
                throw new NotImplementedException();
            }
            return DelegateCache[deleg];
        }
    }
}
